﻿using Newtonsoft.Json.Linq;
using System;
using System.Drawing;
using xbmc_json_async.System;
using System.Collections;

using System.Collections.Generic;
using xbmc_json_async.Utilities;

namespace xbmc_json_async.Media
{
    /// <summary>
    /// Album list, based on generic list type
    /// </summary>
    public class Albums : List<Album>
    {
        /// <summary>
        /// Loads from json object.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        /// <returns></returns>
        public bool LoadFromJsonObject(JObject jsonObject)
        {
            try
            {
                if (jsonObject["albums"] != null)
                {
                    foreach (JObject item in (JArray)jsonObject["albums"])
                    {
                        base.Add(Album.FromJsonObject(item));
                    }

                    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
                return false;
            }

        }
    }

    public class Album : xbmc_json_async.Types.Audio.Details.Album
    {
        private JObject mJObject;

        /// <summary>
        /// Gets the internal property object.
        /// </summary>
        public JObject InternalPropertyObject 
        { 
            get 
            { 
                return mJObject; 
            }
            
        }

        public Album() { }

        public Album(int id, string label, string thumbnail, string artist, string genre, int year, float rating, JObject propObject)
        {
            throw new NotImplementedException("Use emtpy ctor and call FromJsonObject");
            /*
            Id = id;
            Label = label;
            Thumbnail = thumbnail;
            Artist = artist;
            Genre = genre;
            Year = year;
            Rating = rating;

            jObject = propObject;
             */
        }

        public static Album FromJsonObject(JObject item)
        {

            var album = new Album();
            
            Injector injector = new Injector();
            var vObj = (object)album;
            album = (Album)injector.FillObject(vObj, (object)item);

            return album;
        }

        public override string ToString()
        {
            return label;
        }
    }
}
